package com.yd.mvc.baseController.util;


import java.io.*;

/**
 * 读取配置文件的工具类
 * 
 * @version 0.1
 * @date 2018.1.18
 * 
 */
public class LongTimeUrl {
	public static final String LONG_TIME_PROPERTIES = "version\\long-time.properties";
	public static final String VERSION_WAR_PROPERTIES = "version\\version-war.properties";
	//替换文件内容
	public static void changeProperties(String time,String url){
		try {
			File file=new File(url);
			if(file.exists()){
				file.delete();
				file.createNewFile();
			}
			FileWriter fw = new FileWriter(file);
			fw.append(time);
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	//更新截止时间
	public static void addOrUpdateLong(Long time,String url) throws IOException {
		File file = new File(url);
		FileOutputStream out = null;
		out = new FileOutputStream(file);
		String longtime=""+time;
		out.write(longtime.getBytes());
		out.close();
	}
	//修改文件内容
	public static void addOrUpdateString(String str,String url) throws IOException {
		File file = new File(url);
		FileOutputStream out = null;
		out = new FileOutputStream(file);
		out.write(str.getBytes());
		out.close();
	}
	//获取截止时间
	public static long getVersionTime(String url){
		long end=0;
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(url)));
			String data = null;
			data = br.readLine();
			end=Long.parseLong(data);
		} catch (IOException e) {
			System.exit(0);
			e.printStackTrace();
		}
		return end;
	}
	//获取版本秘钥
	public static String getVersionWar(String url){
		String data="";
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(url)));
			data = br.readLine();
		} catch (IOException e) {
			System.exit(0);
			e.printStackTrace();
		}
		return data;
	}
}
